package Demo5;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadPool{
   private BlockingQueue<Runnable> queue=null;

    public MyThreadPool(int n) {
queue=new ArrayBlockingQueue<Runnable>(1000);
        for (int i = 0; i <1000 ; i++) {
            Thread t=new Thread(()->{
                try {
                    while (true) {
                        Runnable task =queue.take();
                        task.run();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
    t.start();
        }
        }

    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }
}


public class Main13 {
    public static void main(String[] args) throws InterruptedException {
       MyThreadPool pool=new MyThreadPool(10);
        for (int i = 0; i <100 ; i++) {
            int id=i;
         pool.submit(()->{
             System.out.println(Thread.currentThread().getName()+"id:"+id);
         });
        }
    }
}
